//
//  PushView.m
//  29-HomeWork
//
//  Created by 鹏飞罗 on 16/8/23.
//  Copyright © 2016年 罗鹏飞. All rights reserved.
//

#import "PushView.h"
#import "ViewController.h"
#import "SecondViewController.h"
@implementation PushView
- (NSTimeInterval)transitionDuration:(nullable id <UIViewControllerContextTransitioning>)transitionContext {
    return 1;
}
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext {
    ViewController *fromView = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    SecondViewController *toView = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    UIView *containerView = [transitionContext containerView];
    
    [containerView addSubview:toView.view];
    toView.imageView1.hidden= YES;
    toView.label1.hidden= YES;
    
    UIView *guoduView = [fromView.cell.myImageView snapshotViewAfterScreenUpdates:YES];
    guoduView.frame = fromView.cell.myImageView.frame;
    [containerView addSubview:guoduView];
    [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
        [containerView layoutIfNeeded];
        guoduView.frame = toView.imageView1.frame;
    } completion:^(BOOL finished) {
        toView.imageView1.hidden = NO;
        toView.label1.hidden = NO;
        [guoduView removeFromSuperview];
        [transitionContext completeTransition:YES];
    }];
    
    
}
@end
